/*
This do-file includes commands for all figures and tables 2 & 3 in the paper.
Please install grc1leg package by running the following command in the command window, "net install grc1leg"
*/



// Move to working directory
cd "D:\HR_Replication"


// Setup data for replication
global analysis_data HR_analysis_eng


//** Figure 1
use $analysis_data, replace

gen outcome=1 // Generating a temporary variable to count the number of articles by year and group
collapse (sum) sum_outcome=outcome (mean) mean_outcome=outcome, by(year group)
reshape wide sum_outcome mean_outcome, i(year) j(group)
egen sum_aritcle=rowtotal(sum_outcome?)

** Stacked Bar for Sum
#delimit ;
graph bar sum_outcome1 sum_outcome2 sum_outcome3 sum_outcome4,
over(year, label(angle(90)))
legend(lab(1 "Chosun") lab(2 "Joongang") lab(3 "Hankyoreh") lab(4 "Kyunghyang")
cols(4) size(small) colfirst region(lstyle(none)))
stack
graphregion(color(white)) bgcolor(white)
scheme(s2mono)
;
#delimit cr


//** Figure 2
use $analysis_data, replace

gen outcome=n_hr
collapse (sum) sum_outcome=outcome (mean) mean_outcome=outcome, by(year group)
replace sum_outcome=sum_outcome/1000000 // scaling y-axis by dividing the variable by 1,000,000
reshape wide sum_outcome mean_outcome, i(year) j(group)

** Connected Line for Mean
#delimit ;
twoway
(connected mean_outcome1 year, msymbol(Oh))
(connected mean_outcome2 year, msymbol(Dh))
(connected mean_outcome3 year, msymbol(Sh) clpattern(dash))
(connected mean_outcome4 year, msymbol(Th) clpattern(dash))
,
legend(lab(1 "Chosun") lab(2 "Joongang") lab(3 "Hankyoreh") lab(4 "Kyunghyang") cols(4) size(small) colfirst region(lstyle(none)))
graphregion(color(white)) bgcolor(white)
scheme(s2mono)
;
#delimit cr



//** Figure 3
use $analysis_data, replace

collapse n_tp? n_cat?, by(year)

#delimit ;
twoway
(connected n_cat1 year, msymbol(Oh))
(connected n_cat2 year, msymbol(Dh) clpattern(shortdash))
(connected n_cat3 year, msymbol(Sh) clpattern(dash))
(connected n_cat4 year, msymbol(Th) clpattern(dash_dot))
,
title("")
ytitle("") xtitle("")
legend(label(1 "Civil and Political Rights") label(2 "Economic, Social, & Cultural Rights")
label(3 "Minority Rights") label(4 "Implementation Mechanisms")
cols(2) region(lstyle(none))) ylabel(0(1)7)
graphregion(color(white)) bgcolor(white)
scheme(s2mono)
;
#delimit cr



//** Figure 4
use $analysis_data, replace

collapse n_tp? n_cat?, by(year)
#delimit ;
twoway
(connected n_tp1 year, msymbol(Oh))
(connected n_tp2 year, msymbol(Dh) clpattern(shortdash))
(connected n_tp3 year, msymbol(Sh) clpattern(dash))
(connected n_tp4 year, msymbol(Th) clpattern(dash_dot))
,
title("")
ytitle("") xtitle("")
legend(label(1 "Topic 1") label(2 "Topic 2")
label(3 "Topic 3") label(4 "Topic 4")
cols(2) region(lstyle(none))) ylabel(0(1)5)
graphregion(color(white)) bgcolor(white)
scheme(s2mono)
name(fig1, replace)
;
#delimit cr

#delimit ;
twoway
(connected n_tp5 year, msymbol(Oh))
(connected n_tp6 year, msymbol(Dh) clpattern(shortdash))
(connected n_tp7 year, msymbol(Sh) clpattern(dash))
(connected n_tp8 year, msymbol(Th) clpattern(dash_dot))
,
title("")
ytitle("") xtitle("")
legend(label(1 "Topic 5") label(2 "Topic 6")
label(3 "Topic 7") label(4 "Topic 8")
cols(2) region(lstyle(none))) ylabel(0(1)5)
graphregion(color(white)) bgcolor(white)
scheme(s2mono)
name(fig2, replace)
;
#delimit cr

graph combine fig1 fig2, col(2) graphregion(color(white)) ycom
graph display, ysize(8) xsize(14)



//** Figure 5
use $analysis_data, replace

recode group (1 2=1) (3 4=2), gen(ideology)
collapse n_tp?, by(year ideology)

forv i=1/8 {

    local outcome n_tp`i'

    #delimit ;
    twoway
    (connected `outcome' year if ideology==1, msymbol(Oh))
    (connected `outcome' year if ideology==2, msymbol(Th) clpattern(shortdash))
    ,
    title("Topic `i'")
    ytitle("") xtitle("")
    legend(label(1 "Conservative") label(2 "Progressive")
    cols(2) region(lstyle(none)) size(small))
    ylabel(0(1)5)
    graphregion(color(white)) bgcolor(white)
    scheme(s2mono)
    name(tp`i', replace)
    ;
    #delimit cr

}

grc1leg tp1 tp2 tp3 tp4 tp5 tp6 tp7 tp8, col(2) graphregion(color(white)) ycom
graph display, ysize(9) xsize(7)



//** Table 2 - Proportion of Human Rights Topics for Each Newspaper
use $analysis_data, replace

* Generating an indicator variable to denote whether a specific topic was mentioned in an article
foreach i of varlist n_tp? {
    gen d_`i'=(`i'>0)
    }
renvars, presub(d_n_ d_)
drop n_*

collapse d_tp?, by(group)

egen sum_tp=rowtotal(d_tp?)
forv i=1/8 {
    gen p_tp`i'=d_tp`i'/sum_tp
    }

keep group p_tp?

xpose, clear
format v1 v2 v3 v4 %3.2f
drop in 1
rename v1 Chosun
rename v2 Joongang
rename v3 Hankyoreh
rename v4 Kyunghyang



// ** Table 3 - Thirty Most Important Words for South Korean Newspapers
use $analysis_data, replace

* Generating an indicator variable to denote whether a specific keyword was mentioned in an article
foreach i of varlist n_life-n_organization {
    gen d_`i'=(`i'>0)
    }
renvars, presub(d_n_ d_)
drop n_*

collapse (sum) d_life-d_organization, by(group)

xpose, clear
drop in 1
rename v1 Chosun
rename v2 Joongang
rename v3 Hankyoreh
rename v4 Kyunghyang

gen word=""
replace word="life" in 1
replace word="death penalty" in 2
replace word="torture" in 3
replace word="imprisonment" in 4
replace word="human trafficking" in 5
replace word="disappearance" in 6
replace word="arrest" in 7
replace word="prosecutor" in 8
replace word="police" in 9
replace word="movement" in 10
replace word="thought" in 11
replace word="conscience" in 12
replace word="religion" in 13
replace word="association" in 14
replace word="assembly" in 15
replace word="expression" in 16
replace word="trial" in 17
replace word="jurisprudence" in 18
replace word="remedy" in 19
replace word="raparation" in 20
replace word="vote" in 21
replace word="election" in 22
replace word="elected" in 23
replace word="information" in 24
replace word="right to information" in 25
replace word="online" in 26
replace word="privacy" in 27
replace word="safety" in 28
replace word="food" in 29
replace word="housing" in 30
replace word="sanitation" in 31
replace word="income" in 32
replace word="poverty" in 33
replace word="polarization" in 34
replace word="welfare" in 35
replace word="insurance" in 36
replace word="labor" in 37
replace word="labor conditions" in 38
replace word="labor union" in 39
replace word="health" in 40
replace word="healthcare" in 41
replace word="disease" in 42
replace word="education" in 43
replace word="university" in 44
replace word="school" in 45
replace word="corporal punishment" in 46
replace word="ostracized" in 47
replace word="bullying" in 48
replace word="culture" in 49
replace word="science" in 50
replace word="artisticworks" in 51
replace word="sports" in 52
replace word="environment" in 53
replace word="air pollution" in 54
replace word="yellow dust" in 55
replace word="climate" in 56
replace word="greenhouse" in 57
replace word="disabled" in 58
replace word="women" in 59
replace word="children" in 60
replace word="adolescent" in 61
replace word="elderly" in 62
replace word="foreigner" in 63
replace word="migrant woman" in 64
replace word="refugee" in 65
replace word="precarious work" in 66
replace word="laborer" in 67
replace word="soldier" in 68
replace word="sexual minority" in 69
replace word="Korean-Chinese" in 70
replace word="oversees Korean" in 71
replace word="North Korean defector" in 72
replace word="homeless" in 73
replace word="criminal suspects" in 74
replace word="ex-convict" in 75
replace word="leprosy" in 76
replace word="comfort women" in 77
replace word="UN" in 78
replace word="human rights law" in 79
replace word="treaties" in 80
replace word="ratification" in 81
replace word="international law" in 82
replace word="courts" in 83
replace word="domestic law" in 84
replace word="ruling" in 85
replace word="precedent" in 86
replace word="human rights education" in 87
replace word="civil society" in 88
replace word="NGO" in 89
replace word="foundation" in 90
replace word="governance" in 91
replace word="organization" in 92

order word

** Find 30 frequently mentioned words for each news source
local list Chosun Joongang Hankyoreh Kyunghyang
foreach s of local list {
    preserve
    gsort -`s'
    keep word `s'
    keep in 1/30 // Most frequently mentioned top 30 words
    rename word word_`s'
    rename `s' count_`s'
    gen rank=_n
    order rank word_`s' count_`s'
    save frequent_word_`s', replace
    restore
    }

use frequent_word_Chosun, replace
merge 1:1 rank using frequent_word_Joongang, gen(_merge2)
merge 1:1 rank using frequent_word_Hankyoreh, gen(_merge3)
merge 1:1 rank using frequent_word_Kyunghyang, gen(_merge4)
drop _merge*
order rank word* count*
